﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using WebApplication11.Dao;
using WebApplication11.Services;

namespace WebApplication11.Controllers;

public class detailController : Controller
{
    private detailService _detailService = new detailService();
    public bool Auth()
    {
        if (HttpContext.Session.GetInt32("Status") == 1)
        {
            return true;
        }
        return false;
    }
    // GET
    public IActionResult Index()
    {
        if (!Auth())
        {
            return RedirectToAction("Index", "Home");
        }
        ViewBag.username = HttpContext.Session.GetString("user");
        ViewBag.Forests = _detailService.getForests(HttpContext.Session.GetString("user"));
        return View();
    }

    public IActionResult changePassword(string password)
    {
        _detailService.changePassword(HttpContext.Session.GetString("user"), password);
        return RedirectToAction("Index", "detail");
    }

    public IActionResult destory()
    {
        _detailService.destory(HttpContext.Session.GetString("user"));
        return RedirectToAction("Index");
    }
}